<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>yaml数据驱动案例 | 移动端测试课程介绍</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-chapter-fold/chapter-fold.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../day6/readme.html" />
    
    
    <link rel="prev" href="../day5/pyyaml.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="5.3"
        data-chapter-title="yaml数据驱动案例"
        data-filepath="day5/yaml_data.md"
        data-basepath=".."
        data-revision="Sat Jun 08 2019 07:44:25 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="day1/readme.html">
            
                
                    <a href="../day1/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        移动入门
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="day1/app_test_knowledge.html">
            
                
                    <a href="../day1/app_test_knowledge.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        移动端测试概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="day1/create_env/readme.html">
            
                
                    <a href="../day1/create_env/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        移动测试环境搭建搭建
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="day1/create_env/java.html">
            
                
                    <a href="../day1/create_env/java.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.1.</b>
                        
                        Java环境搭建
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="day1/create_env/sdk.html">
            
                
                    <a href="../day1/create_env/sdk.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.2.</b>
                        
                        Android sdk 环境
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="day1/create_env/geny.html">
            
                
                    <a href="../day1/create_env/geny.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.3.</b>
                        
                        Android 虚拟机安装
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="day1/command_adb.html">
            
                
                    <a href="../day1/command_adb.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        ADB命令
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="day1/app_tools.html">
            
                
                    <a href="../day1/app_tools.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        移动端自动化工具
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="day1/appium_env.html">
            
                
                    <a href="../day1/appium_env.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        appium环境搭建
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="day1/start_appium.html">
            
                
                    <a href="../day1/start_appium.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        appium入门案例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="day2/readme.html">
            
                
                    <a href="../day2/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        app操作api
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="day2/base_api.html">
            
                
                    <a href="../day2/base_api.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        app基础操作api
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="day2/uiauto.html">
            
                
                    <a href="../day2/uiauto.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        uiautomatorviewer工具
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="day2/location_element.html">
            
                
                    <a href="../day2/location_element.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        app元素定位操作api
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="day2/get_infor.html">
            
                
                    <a href="../day2/get_infor.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        根据元素获取信息api
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="day2/element_event.html">
            
                
                    <a href="../day2/element_event.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        元素事件操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="day2/touch_action.html">
            
                
                    <a href="../day2/touch_action.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        模拟手势操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="day2/phone_api.html">
            
                
                    <a href="../day2/phone_api.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        手机操作api
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="day3/readme.html">
            
                
                    <a href="../day3/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Pytest
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="day3/install_introduction.html">
            
                
                    <a href="../day3/install_introduction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        pytest安装和介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="day3/setup_teardown.html">
            
                
                    <a href="../day3/setup_teardown.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        setup和teardown函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="day3/pytest_config.html">
            
                
                    <a href="../day3/pytest_config.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        pytest的配置文件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="day3/middle.html">
            
                
                    <a href="../day3/middle.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        pytest常用插件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="day3/pytest_prov1.html">
            
                
                    <a href="../day3/pytest_prov1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        pytest提高1--fixture
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="day3/pytest_prov2.html">
            
                
                    <a href="../day3/pytest_prov2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        pytest提高2
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="day4/readme.html">
            
                
                    <a href="../day4/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        PO模式
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="day4/introduction.html">
            
                
                    <a href="../day4/introduction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        PO模式介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="day4/project_plan.html">
            
                
                    <a href="../day4/project_plan.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        项目准备
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="day4/logic.html">
            
                
                    <a href="../day4/logic.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        按照业务抽取代码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="day4/find_element.html">
            
                
                    <a href="../day4/find_element.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        抽取的find_element
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="day4/base_action.html">
            
                
                    <a href="../day4/base_action.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        抽取基础动作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="day5/readme.html">
            
                
                    <a href="../day5/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        数据驱动--Yaml
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="day5/introduction_yaml.html">
            
                
                    <a href="../day5/introduction_yaml.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        Yaml介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="day5/pyyaml.html">
            
                
                    <a href="../day5/pyyaml.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        python解析yaml文件
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="5.3" data-path="day5/yaml_data.html">
            
                
                    <a href="../day5/yaml_data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        yaml数据驱动案例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="day6/readme.html">
            
                
                    <a href="../day6/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        Allure报告和Jenkins集成
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="day6/allure.html">
            
                
                    <a href="../day6/allure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        allure介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="day6/pytest_allure.html">
            
                
                    <a href="../day6/pytest_allure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        pytest中使用allure
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="day6/jenkins.html">
            
                
                    <a href="../day6/jenkins.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        Jenkins安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="day6/jenkins_git_allure_email.html">
            
                
                    <a href="../day6/jenkins_git_allure_email.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        Jenkins持续集成配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >移动端测试课程介绍</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="yaml&#x6570;&#x636E;&#x9A71;&#x52A8;&#x6848;&#x4F8B;">yaml&#x6570;&#x636E;&#x9A71;&#x52A8;&#x6848;&#x4F8B;</h1>
<h2 id="&#x5B66;&#x4E60;&#x76EE;&#x6807;">&#x5B66;&#x4E60;&#x76EE;&#x6807;</h2>
<ul>
<li>&#x638C;&#x63E1;&#x5982;&#x4F55;&#x5728;&#x9879;&#x76EE;&#x4E2D;&#x4F7F;&#x7528;yaml&#x52A8;&#x6001;&#x4FEE;&#x6539;&#x6570;&#x636E;</li>
</ul>
<h3 id="1&#x4EC0;&#x4E48;&#x662F;&#x6570;&#x636E;&#x9A71;&#x52A8;">1.&#x4EC0;&#x4E48;&#x662F;&#x6570;&#x636E;&#x9A71;&#x52A8;</h3>
<blockquote>
<p>&#x5C06;&#x6D4B;&#x8BD5;&#x811A;&#x672C;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x72EC;&#x7ACB;&#x51FA;&#x6765;,&#x5355;&#x72EC;&#x5B58;&#x653E;&#x5230;&#x6587;&#x4EF6;&#x4E2D;,&#x4FBF;&#x4E8E;&#x5BF9;&#x6570;&#x636E;&#x7684;&#x7BA1;&#x7406;. </p>
</blockquote>
<h3 id="2&#x6D4B;&#x8BD5;&#x9879;&#x76EE;">2.&#x6D4B;&#x8BD5;&#x9879;&#x76EE;</h3>
<p>&#x9700;&#x6C42;:</p>
<ol>
<li>&#x8FDB;&#x5165;&#x8BBE;&#x7F6E;&#x70B9;&#x51FB;&#x641C;&#x7D22;&#x6309;&#x94AE;</li>
<li>&#x8F93;&#x5165;&#x641C;&#x7D22;&#x5185;&#x5BB9;</li>
<li>&#x70B9;&#x51FB;&#x8FD4;&#x56DE;</li>
</ol>
<h3 id="3&#x5B8C;&#x6210;&#x540E;&#x76EE;&#x5F55;&#x7ED3;&#x6784;">3.&#x5B8C;&#x6210;&#x540E;&#x76EE;&#x5F55;&#x7ED3;&#x6784;</h3>
<pre><code class="lang-python">search_content <span class="hljs-comment"># &#x9879;&#x76EE;</span>
- base
    - __init__.py <span class="hljs-comment"># &#x521D;&#x59CB;&#x5316;&#x6587;&#x4EF6;</span>
  - base_action.py <span class="hljs-comment"># &#x5C01;&#x88C5;&#x7684;&#x57FA;&#x672C;&#x64CD;&#x4F5C;</span>
  - base_driver.py <span class="hljs-comment"># &#x9A71;&#x52A8;&#x521D;&#x59CB;&#x5316;</span>
  - read_data.py <span class="hljs-comment"># &#x6570;&#x636E;&#x89E3;&#x6790;&#x6587;&#x4EF6;</span>
- data
    - search_data.yaml
- page
    - search_page.py
-    script
    - test_search.py
- pytest.ini
</code></pre>
<h3 id="4-&#x4EE3;&#x7801;">4. &#x4EE3;&#x7801;</h3>
<h4 id="41-&#x521B;&#x5EFA;data&#x76EE;&#x5F55;&#x521B;&#x5EFA;searchdatayaml">4.1 &#x521B;&#x5EFA;data&#x76EE;&#x5F55;,&#x521B;&#x5EFA;search_data.yaml</h4>
<pre><code class="lang-yaml">search_test_001:
  input_text: &quot;&#x4F60;&#x597D;&quot;
search_test_002:
  input_text: &quot;1234&quot;
seearch_test_003:
  input_text: &quot;*&amp;^%&quot;
</code></pre>
<h4 id="42-&#x521B;&#x5EFA;basereaddatapy-&#x89E3;&#x6790;&#x6570;&#x636E;">4.2 &#x521B;&#x5EFA;base/read_data.py &#x89E3;&#x6790;&#x6570;&#x636E;</h4>
<p>Read_data.py</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> yaml
<span class="hljs-keyword">import</span> os

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ReadData</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__int__</span><span class="hljs-params">(self, filename)</span>:</span>
        self.path = os.getcwd() + os.sep + <span class="hljs-string">&quot;data&quot;</span> + os.sep + filename

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">return_data</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-keyword">with</span> open(self.path, <span class="hljs-string">&quot;r&quot;</span>) <span class="hljs-keyword">as</span> f:
            data = yaml.load(f)
            <span class="hljs-keyword">return</span> data
</code></pre>
<p>Base_action.py</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BaseAction</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, driver)</span>:</span>
        self.driver = driver

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">click_element</span><span class="hljs-params">(self, loc)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;&#x70B9;&#x51FB;&#x7684;&#x57FA;&#x672C;&#x64CD;&#x4F5C;&quot;&quot;&quot;</span>
        self.find_element(loc).click()

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">input_element_content</span><span class="hljs-params">(self, loc, content)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;&#x8F93;&#x5165;&#x6846;&#x7684;&#x57FA;&#x672C;&#x64CD;&#x4F5C;&quot;&quot;&quot;</span>
        self.find_element(loc).clear()
        self.find_element(loc).send_keys(content)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">find_element</span><span class="hljs-params">(self, loc)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;&#x62BD;&#x53D6;&#x67E5;&#x627E;&#x5143;&#x7D20;&#x7684;&#x57FA;&#x672C;&#x52A8;&#x4F5C;&quot;&quot;&quot;</span>
        self.driver.implicitly_wait(<span class="hljs-number">10</span>)
        <span class="hljs-keyword">return</span> self.driver.find_element(loc[<span class="hljs-number">0</span>], loc[<span class="hljs-number">1</span>])
</code></pre>
<p>Base_driver.py</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> appium <span class="hljs-keyword">import</span> webdriver


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">init_driver</span><span class="hljs-params">(app_package, app_activity)</span>:</span>
    desired_caps = dict()
    <span class="hljs-comment"># &#x6D4B;&#x8BD5;&#x8BBE;&#x5907;&#x4FE1;&#x606F;</span>
    desired_caps[<span class="hljs-string">&apos;platformName&apos;</span>] = <span class="hljs-string">&apos;Android&apos;</span>
    desired_caps[<span class="hljs-string">&apos;platformVersion&apos;</span>] = <span class="hljs-string">&apos;5.1&apos;</span>
    desired_caps[<span class="hljs-string">&apos;deviceName&apos;</span>] = <span class="hljs-string">&apos;192.168.56.101:5555&apos;</span>
    <span class="hljs-comment"># app&#x4FE1;&#x606F;</span>
    desired_caps[<span class="hljs-string">&apos;appPackage&apos;</span>] = app_package <span class="hljs-comment"># &#x62BD;&#x53D6;&#x4E3A;&#x5E38;&#x91CF;</span>
    desired_caps[<span class="hljs-string">&apos;appActivity&apos;</span>] = app_activity <span class="hljs-comment"># &#x62BD;&#x53D6;&#x4E3A;&#x5E38;&#x91CF;</span>

    <span class="hljs-comment"># &#x8FD4;&#x56DE;&#x9A71;&#x52A8;&#x5BF9;&#x8C61;</span>
    <span class="hljs-keyword">return</span>  webdriver.Remote(<span class="hljs-string">&apos;http://127.0.0.1:4723/wd/hub&apos;</span>, desired_caps)
</code></pre>
<p><strong>init</strong>.py</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> appium.webdriver.webdriver <span class="hljs-keyword">import</span> By

<span class="hljs-string">&quot;&quot;&quot;
1.&#x5E94;&#x7528;&#x7684;&#x5305;&#x540D;&#x548C;&#x542F;&#x52A8;&#x540D;
&quot;&quot;&quot;</span>
app_package = <span class="hljs-string">&apos;com.android.settings&apos;</span>
app_activity = <span class="hljs-string">&quot;.Settings&quot;</span>

<span class="hljs-string">&quot;&quot;&quot;
2.&#x641C;&#x7D22;
&quot;&quot;&quot;</span>
search_button = (By.XPATH, <span class="hljs-string">&quot;//*[@content-desc=&apos;&#x641C;&#x7D22;&apos;]&quot;</span>)
search_edit_text = (By.CLASS_NAME, <span class="hljs-string">&quot;android.widget.EditText&quot;</span>)
back_button = (By.CLASS_NAME, <span class="hljs-string">&quot;android.widget.ImageButton&quot;</span>)
</code></pre>
<h4 id="43-&#x7F16;&#x5199;&#x6D4B;&#x8BD5;&#x811A;&#x672C;scripttestsearchpy">4.3 &#x7F16;&#x5199;&#x6D4B;&#x8BD5;&#x811A;&#x672C;script/test_search.py</h4>
<p>Test_search.py</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> base
<span class="hljs-keyword">import</span> pytest
<span class="hljs-keyword">from</span> page.search_page <span class="hljs-keyword">import</span> SearchPage
<span class="hljs-keyword">from</span> base.base_driver <span class="hljs-keyword">import</span> init_driver
<span class="hljs-keyword">from</span> base.read_data <span class="hljs-keyword">import</span> ReadData

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">package_param_data</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;&#x89E3;&#x6790;&#x6570;&#x636E;&quot;&quot;&quot;</span>
    yaml_data = ReadData(<span class="hljs-string">&apos;search_data.yaml&apos;</span>).return_data()
    list_data = []
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> yaml_data.keys():
        list_data.append((i, yaml_data.get(i).get(<span class="hljs-string">&apos;input_text&apos;</span>)))
    <span class="hljs-keyword">return</span> list_data


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test_Search</span>:</span>
  <span class="hljs-string">&apos;&apos;&apos;&#x6D4B;&#x8BD5;&#x811A;&#x672C;&apos;&apos;&apos;</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">setup_class</span><span class="hljs-params">(self)</span>:</span>
        self.driver = init_driver(base.app_package, base.base_driver)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">teardown_class</span><span class="hljs-params">(self)</span>:</span>
        self.driver.quit()

<span class="hljs-decorator">    @pytest.mark.parametrize(&apos;test_id, input_text&apos;, package_param_data())</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_search</span><span class="hljs-params">(self, test_id, input_text)</span>:</span>
        sp = SearchPage(self.driver)
        <span class="hljs-comment"># &#x8C03;&#x7528;&#x64CD;&#x4F5C;&#x7C7B;</span>
        <span class="hljs-comment"># print(&quot;test_id:&quot;, test_id)</span>
        sp.input_search(input_text)
</code></pre>
<h4 id="44--&#x7F16;&#x5199;searchpagepy">4.4  &#x7F16;&#x5199;search_page.py</h4>
<p>&#x5C01;&#x88C5;&#x7684;&#x662F;&#x641C;&#x7D22;&#x7684;&#x529F;&#x80FD;</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> base
<span class="hljs-keyword">from</span> base.base_action <span class="hljs-keyword">import</span> BaseAction


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SearchPage</span><span class="hljs-params">(BaseAction)</span>:</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">click_search</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;&#x70B9;&#x51FB;&#x641C;&#x7D22;&#x6309;&#x94AE;&quot;&quot;&quot;</span>
        self.click_element(base.search_button)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">input_search</span><span class="hljs-params">(self, text)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;&#x8F93;&#x5165;&#x641C;&#x7D22;&#x5185;&#x5BB9;&quot;&quot;&quot;</span>
        self.input_element_content(base.search_edit_text, text)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">click_back</span><span class="hljs-params">(self)</span>:</span>
        self.click_element(base.back_button)
</code></pre>
<h4 id="45-pytest&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;">4.5 pytest&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</h4>
<p>Pytest.ini</p>
<pre><code class="lang-ini"><span class="hljs-title">[pytest]</span>
<span class="hljs-setting">addopts = <span class="hljs-value">-s</span></span>
<span class="hljs-setting">test_path = <span class="hljs-value">./script</span></span>
<span class="hljs-setting">python_files = <span class="hljs-value">test_*</span></span>
<span class="hljs-setting">python_classes = <span class="hljs-value">Test*</span></span>
<span class="hljs-setting">python_functions = <span class="hljs-value">test_*</span></span>
</code></pre>
<h3 id="5-&#x603B;&#x7ED3;">5. &#x603B;&#x7ED3;</h3>
<p>&#x7ECF;&#x8FC7;&#x5B9E;&#x73B0;&#x6211;&#x4EEC;&#x53D1;&#x73B0;&#x5F88;&#x591A;&#x4EE3;&#x7801;&#x90FD;&#x662F;&#x91CD;&#x590D;&#x7684;,&#x53D8;&#x5316;&#x7684;&#x53EA;&#x662F;&#x8981;&#x8FDB;&#x884C;&#x6D4B;&#x8BD5;&#x7684;&#x529F;&#x80FD;&#x6A21;&#x5757;,&#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5BF9;&#x6B64;&#x67B6;&#x6784;&#x8FDB;&#x884C;&#x91CD;&#x590D;&#x4F7F;&#x7528;,&#x66F4;&#x6539;&#x7684;&#x53EA;&#x662F;&#x6D4B;&#x8BD5;&#x811A;&#x672C;&#x6587;&#x4EF6;&#x3001;&#x641C;&#x7D22;&#x529F;&#x80FD;&#x7684;&#x96C6;&#x4F53;&#x5B9E;&#x73B0;.</p>
<p>&#x65B0;&#x589E;&#x7684;&#x662F;&#x6570;&#x636E;&#x9A71;&#x52A8;&#x8FD9;&#x4E00;&#x5757;,&#x540E;&#x9762;&#x4E5F;&#x53EF;&#x4EE5;&#x91CD;&#x590D;&#x4F7F;&#x7528;.&#x91CD;&#x70B9;&#x8981;&#x638C;&#x63E1;yaml&#x7684;&#x6570;&#x636E;&#x9A71;&#x52A8;&#x5B9E;&#x73B0;.</p>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../day5/pyyaml.html" class="navigation navigation-prev " aria-label="Previous page: python解析yaml文件"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../day6/readme.html" class="navigation navigation-next " aria-label="Next page: Allure报告和Jenkins集成"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"expandable-chapters-small":{},"splitter":{},"chapter-fold":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
